package myjava.File;

import java.io.File;

// ReName-File
public class RenameFileExample {
	public static void main(String[] args) {

		// Directory path here
		String path = ".";

		String files;
		File folder = new File(path);
		File[] listOfFiles = folder.listFiles();

		for (int i = 0; i < listOfFiles.length; i++) {

			if (listOfFiles[i].isFile()) {
				String fileName = listOfFiles[i].getName();
				if (fileName.endsWith(".txt")) {
					fileName = fileName.replaceAll(".txt", ".text");
					// System.out.println(fileName);
					listOfFiles[i].renameTo(new File(fileName));
				}

				files = listOfFiles[i].getName();
				System.out.println(files);
			}
		}
	}
}
